package LeetCode;

import java.util.*;

/**
 * @Author: fzykd
 * Date: 2024-04-13
 * Time: 21:05
 * User: LQH
 */


//异位词分组
public class Heterotopic {

    public static List<List<String>> groupAnagrams(String[] strs) {
        Map<String, List<String>> hashMap = new HashMap<>();
        for (String str : strs) {
            char[] chars = str.toCharArray();
            Arrays.sort(chars);
            String key = new String(chars);
            List<String> item = hashMap.getOrDefault(key, new ArrayList<>());
            item.add(str);
            hashMap.put(key, item);
        }
        return new ArrayList<>(hashMap.values());
    }


    public static void main(String[] args) {
        String[] str = {"eat", "tea", "tan", "ate", "nat", "bat"};
        groupAnagrams(str);
    }

}


